import imagereader.IImageProcessor;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.FilteredImageSource;
import java.awt.image.RGBImageFilter;

public class ImageProcessorImpl implements IImageProcessor {

	public static final int ChanelR = 0;
	public static final int ChanelG = 1;
	public static final int ChanelB = 2;
	
	@Override
	public Image showChanelB(Image img) {
		// return BMPLoader.createColorChanel(arg0, BMPLoader.ChanelR);
        Toolkit kit = Toolkit.getDefaultToolkit();  
        Image newimg = kit.createImage(
        		new FilteredImageSource(img.getSource(), new MyColorFilter(ChanelB)));  
        return newimg;
	}

	@Override
	public Image showChanelG(Image img) {
        Toolkit kit = Toolkit.getDefaultToolkit();  
        Image newimg = kit.createImage(
        		new FilteredImageSource(img.getSource(), new MyColorFilter(ChanelG)));  
        return newimg;
	}

	@Override
	public Image showChanelR(Image img) {
        Toolkit kit = Toolkit.getDefaultToolkit();  
        Image newimg = kit.createImage(
        		new FilteredImageSource(img.getSource(), new MyColorFilter(ChanelR)));  
        return newimg;
	}

	@Override
	public Image showGray(Image img) {
		// TODO Auto-generated method stub
		return null;
	}
	
    class MyColorFilter extends RGBImageFilter  
    {  
    	private int chanel;
    	
        public MyColorFilter(int chanel)  
        {  
        	this.chanel = chanel;
            canFilterIndexColorModel = true;  
        }  
        public int filterRGB(int x, int y, int rgb)  
        {  
        	if(this.chanel == ChanelR) {
        		return (rgb & 0xffff0000);  
        	}
        	else if(this.chanel == ChanelG) {
        		return (rgb & 0xff00ff00);  
        	}
        	else {
        		return (rgb & 0xff0000ff);  
        	}
        }  
    }  
      

//	public Image getImageByChanel(Image img, int chanel) {
//		BufferedImage buffImg = BMPUtil.convertFromImage(img);
//		int width = buffImg.getWidth();
//		int height = buffImg.getHeight();
//		int minx = buffImg.getMinX();
//		int miny = buffImg.getMinY();
//		
//		for (int i = minx; i < width; i++) {
//			for (int j = 0; j < height; j++) {
//				
//				
//			}
//		}
//
//	}

}
